package cn.kimming.wms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kimming.wms.dao.IOrderBillDAO;
import cn.kimming.wms.dao.ISupplierDAO;
import cn.kimming.wms.domain.OrderBill;
import cn.kimming.wms.domain.Supplier;
import cn.kimming.wms.excep.ObjectIsUsedException;
import cn.kimming.wms.query.QueryObject;
import cn.kimming.wms.service.ISupplierService;

@Service("supplierService")
public class SupplierServiceImpl implements ISupplierService {

	@Autowired
	private ISupplierDAO supplierDAO;
	@Autowired
	private IOrderBillDAO orderBillDAO;
	
	@Override
	public void save(Supplier obj) {
		supplierDAO.save(obj);
	}

	@Override
	public void update(Supplier obj) {
		supplierDAO.update(obj);
	}

	@Override
	public void delete(Long id) {
		List<OrderBill> children = orderBillDAO.listBySupplierId(id);
		if (children.size() > 0) {
			throw new ObjectIsUsedException();
		}
		supplierDAO.delete(supplierDAO.get(id));
		
	}

	@Override
	public Supplier get(Long id) {
		return supplierDAO.get(id);
	}

	@Override
	public List<Supplier> list() {
		return supplierDAO.list();
	}

	@Override
	public List<Supplier> query(QueryObject qo) {
		return supplierDAO.query(qo);
	}
}
